import winston from 'winston'
import PROJECT from '../PROJECT'

const createLogger = ({ accessFile, errorFile }) => winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`),
  ),
  defaultMeta: { service: 'app' },
  transports: [
    new winston.transports.File({ filename: errorFile, level: 'error' }),
    new winston.transports.File({ filename: accessFile })
  ]
})

export default createLogger({
  accessFile: PROJECT.LOG.ACCESS,
  errorFile: PROJECT.LOG.ERROR
})